package basic01.process;

import java.util.Scanner;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/16 15:35
 * @description 流程结构
 */
public class ProcessStruct {

    public static void main(String[] args) {

        // 自上而下的结构(顺序结构) ↓
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入值");
        String s = scanner.nextLine();

        // 选择结构 ☑ 满足条件不执行
        if ("hello".equals(s)) {
            System.out.println("s = " + s);
        } else {
            System.out.println("输入不对");
        }

        // switch 多选址结构(字符串)
        char grade = 'A';
        switch (grade) {
            case 'A':
                System.out.println("grade = " + grade);
                break;
            default:
                System.out.println("未知");
        }

        // switch 多选址结构(字符串)
        String str = "王云";
        switch (str) {
            case "王云":
                System.out.println("str = " + str);
                break;
            default:
                System.out.println("未知");
        }

        // 循环结构(while/for/do...while)
        int iii = 0;
        int sum = 0;
        while (iii < 100) {
            iii++;
            System.out.println("iii = " + iii);
        }

        // while循环
        while (iii < 100) {
            sum = sum + iii;
            iii++;
        }
        System.out.println("sum = " + sum);

        //  do{}while(); 循环
        do {
            sum = sum + iii;
            iii++;
        } while (iii < 100);
        System.out.println("sum = " + sum);

        // for循环 初始化;条件判断;迭代(通用结构)
        for (iii = 0; iii < 100; iii++) {
            iii++;
            sum = sum + iii;
        }
        System.out.println("sum = " + sum);

        // 奇数和偶数之和
        int ouSum = 0;
        int jiSum = 0;
        for (int i = 0; i <= 100; i++) {
            if (i % 2 == 0) {
                ouSum = ouSum + i;
            } else {
                jiSum = jiSum + i;
            }
        }
        System.out.println("偶数和 : " + ouSum);
        System.out.println("奇数和 : " + jiSum);

        // 1000被5整除的
        for (int i = 0; i < 1000; i++) {
            if (i % 5 == 0) {
                System.out.print(i + "\t");
            }

            if (i % (5 * 3) == 0) {
                System.out.println();
            }
        }

        // 九九乘法表(打印第一列/循环/去掉重复项/调整样式)
        for (int j = 1; j <= 9; j++) {
            for (int i = 1; i <= j; i++) {
                System.out.print(j + "*" + i + "=" + (j * i) + "\t");
            }
            System.out.println();
        }

        // for增强(循环数组和集合)
        int[] nums = {1, 2, 3, 4, 5};
        for (int num : nums) {
            System.out.println("num = " + num);
        }

        // break(强制退出循环)和continue(退出某次循环)

        // 打印三角形(5)
        for (int i = 1; i <= 5; i++) {
            for (int j = 5; j >= i; j--) {
                System.out.println(" ");
            }
            for (int j = 1; j <= i; j++) {
                System.out.println("*");
            }
            for (int j = 1; j < i; j++) {
                System.out.println("*");
            }
            System.out.println();
        }
    }
}

